/* Filename: creat2.c
 * Description: <TODO>
 * $ gcc -Wall creat2.c -o creat2 -lpthread
 * Last modified: humble 20200418 15:39
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>

static void usage(void);

static void *thr_func(void *arg)
{
    while(1)
        pause();
    pthread_exit(NULL);
}

int main(int argc, char **argv)
{
    int i, err;
    pthread_t tid;
    pthread_attr_t attr;

    if(argc != 1){
        fprintf(stderr, "argc !=1");
        usage();
        exit(1);
    }

    pthread_attr_init(&attr);
    pthread_attr_setstacksize(&attr, 1024 * 1024);

    for(i = 0;  ; i++)
    {
        err = pthread_create(&tid, &attr, thr_func, NULL);
        if(err){
            fprintf(stderr, "pthread_create():%s\n", strerror(err));
            break;
        }
    }

    printf("%d\n", i);

    pthread_attr_destroy(&attr);
    return 0;
}

static void usage(void)
{
#define USAGE "Usage:\n\
  Helloworld\n"
    printf(USAGE);
}
